

import java.awt.*;
import java.awt.event.KeyEvent;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.swing.JTable;
import javax.swing.KeyStroke;
import net.java.dev.jaxb.array.StringArray;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Stefano
 */
public class NuovaAnagrafica extends javax.swing.JDialog {
    private final Frame parent2;
    private final Integer tipo2;
   
    private boolean ans=false;

    /**
     * Creates new form AnagraficaInserisci l'int sta per
     * 1=fornitore,2=cliente,3=agente
     */
    public NuovaAnagrafica(java.awt.Frame parent, boolean modal,Integer tipo) {
        super(parent, modal);
        parent2=parent;
        tipo2=tipo;
        
        initComponents();
        Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
		this.setLocation(new Point(
				(dimension.width - this.getSize().width) / 2,
				(dimension.height - this.getSize().height) / 2));
        this.setTitolo(tipo);
        this.nome.requestFocus();
    }



    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pannelloInfo = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        nome = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        piva = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        tel1 = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        jToggleButton3 = new javax.swing.JToggleButton();
        jToggleButton5 = new javax.swing.JToggleButton();
        jPanel3 = new javax.swing.JPanel();
        titolo = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        Salva = new javax.swing.JButton();
        ind = new javax.swing.JTextField();
        tel2 = new javax.swing.JTextField();
        tel3 = new javax.swing.JTextField();
        em1 = new javax.swing.JTextField();
        em2 = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        cognome = new javax.swing.JTextField();
        jLabel27 = new javax.swing.JLabel();
        rsoc = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("inserisci anagrafica");

        pannelloInfo.setBackground(new java.awt.Color(255, 255, 255));
        pannelloInfo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel21.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jLabel21.setText("Nome ");

        nome.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                nomeKeyPressed(evt);
            }
        });

        jLabel22.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jLabel22.setText("Partita IVA");

        jLabel23.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jLabel23.setText("indirizzo");

        piva.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                pivaKeyPressed(evt);
            }
        });

        jLabel24.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jLabel24.setText("Telefono");

        tel1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tel1KeyPressed(evt);
            }
        });

        jLabel25.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jLabel25.setText("Email");

        jToggleButton3.setToolTipText("Cerca Modello Base");
        jToggleButton3.setBorder(null);
        jToggleButton3.setContentAreaFilled(false);
        jToggleButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jToggleButton3MouseClicked(evt);
            }
        });

        jToggleButton5.setToolTipText("Cerca Linea");
        jToggleButton5.setBorder(null);
        jToggleButton5.setContentAreaFilled(false);
        jToggleButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jToggleButton5MouseClicked(evt);
            }
        });

        jPanel3.setBackground(new java.awt.Color(0, 51, 204));

        titolo.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        titolo.setForeground(new java.awt.Color(255, 255, 255));
        titolo.setText("Info ");

        jPanel7.setBackground(new java.awt.Color(204, 204, 204));
        jPanel7.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        Salva.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Save.png"))); // NOI18N
        Salva.setToolTipText("Salva");
        Salva.setBorderPainted(false);
        Salva.setContentAreaFilled(false);
        Salva.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                SalvaMouseClicked(evt);
            }
        });
        Salva.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                SalvaKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(Salva, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(Salva)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titolo)
                .addContainerGap(243, Short.MAX_VALUE))
            .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(titolo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        ind.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                indKeyPressed(evt);
            }
        });

        tel2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tel2KeyPressed(evt);
            }
        });

        tel3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tel3KeyPressed(evt);
            }
        });

        em1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                em1KeyPressed(evt);
            }
        });

        em2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                em2KeyPressed(evt);
            }
        });

        jLabel26.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jLabel26.setText("Cognome");

        cognome.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cognomeKeyPressed(evt);
            }
        });

        jLabel27.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jLabel27.setText("R.Sociale");

        rsoc.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                rsocKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout pannelloInfoLayout = new javax.swing.GroupLayout(pannelloInfo);
        pannelloInfo.setLayout(pannelloInfoLayout);
        pannelloInfoLayout.setHorizontalGroup(
            pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pannelloInfoLayout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(pannelloInfoLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pannelloInfoLayout.createSequentialGroup()
                        .addGap(396, 396, 396)
                        .addComponent(jToggleButton5))
                    .addGroup(pannelloInfoLayout.createSequentialGroup()
                        .addComponent(jLabel27)
                        .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(pannelloInfoLayout.createSequentialGroup()
                                .addGap(345, 345, 345)
                                .addComponent(jToggleButton3))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pannelloInfoLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(rsoc, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(176, 176, 176))))
                    .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pannelloInfoLayout.createSequentialGroup()
                                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel26)
                                    .addComponent(jLabel25, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(cognome)
                                    .addComponent(ind)
                                    .addComponent(piva)
                                    .addComponent(tel1)
                                    .addComponent(tel2)
                                    .addComponent(tel3)
                                    .addComponent(em1)
                                    .addComponent(em2, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jLabel23)
                            .addComponent(jLabel22)
                            .addComponent(jLabel24, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pannelloInfoLayout.createSequentialGroup()
                            .addComponent(jLabel21)
                            .addGap(64, 64, 64)
                            .addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        pannelloInfoLayout.setVerticalGroup(
            pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pannelloInfoLayout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jToggleButton5)
                .addGap(9, 9, 9)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToggleButton3)
                    .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel27)
                        .addComponent(rsoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(6, 6, 6)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel21))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel26)
                    .addComponent(cognome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(ind, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(piva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel24))
                .addGap(7, 7, 7)
                .addComponent(tel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(em1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel25))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(em2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(78, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(pannelloInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 287, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(pannelloInfo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    //modifica il titolo    
    public boolean risposta(){return ans;}
    
    private void setTitolo(Integer tipo){
     switch (tipo) {
            case 1:  titolo.setText("Inserisci Fornitore");
                     break;
            case 2:  titolo.setText("Inserisci Cliente");
                     break;
            case 3:  titolo.setText("Inserisci Agente");    
            
        }
    }
    
    private void jToggleButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jToggleButton3MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton3MouseClicked

    private void jToggleButton5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jToggleButton5MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton5MouseClicked

    private void SalvaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SalvaMouseClicked
     Confermasalva cs = new Confermasalva(parent2,true);
    cs.setVisible(true);
   if (cs.risposta()) {//se la form di conferma e' ok 
         String identificativo;
         if(this.rsoc.getText()==""){//controlla se c'e' solo la ragione sociale invece che un nominativo
          identificativo=this.cognome.getText()+" "+this.nome.getText();
         }
         else{
             identificativo=this.rsoc.getText()+" "+this.cognome.getText()+" "+this.nome.getText();
         }
              if (controllo(this.piva.getText(), "piva"))
         
           if (inserimento(identificativo,this.ind.getText(),this.piva.getText(),
                  this.tel1.getText(),this.tel2.getText(),this.tel3.getText(),this.em1.getText(),this.em2.getText(),tipo2)
              )
               
           {Errore err = new Errore (parent2,true);
               err.settitolo("Operazione Eseguita");
               err.setmessaggio("Record Salvato");
               err.setVisible(true);
               ans=true;
               this.setVisible(false);
               
               } 
           else {Errore err = new Errore (parent2,true);
               err.setmessaggio("Controlla i campi");
               err.setVisible(true);}
           else {Errore err = new Errore (parent2,true);
               err.setmessaggio("Partita iva già presente in archivio");
               err.setVisible(true);
         }  
   }
       // TODO add your handling code here:
    }//GEN-LAST:event_SalvaMouseClicked

    private void nomeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nomeKeyPressed
     if (evt.getKeyCode() == KeyEvent.VK_DOWN | evt.getKeyCode() == KeyEvent.VK_ENTER) {
       this.cognome.requestFocusInWindow();}
     if (evt.getKeyCode() == KeyEvent.VK_UP) {
       this.rsoc.requestFocusInWindow();}// TODO add your handling code here:
    }//GEN-LAST:event_nomeKeyPressed

    private void cognomeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cognomeKeyPressed
     if (evt.getKeyCode() == KeyEvent.VK_DOWN | evt.getKeyCode() == KeyEvent.VK_ENTER) {
       this.ind.requestFocusInWindow();}
     if (evt.getKeyCode() == KeyEvent.VK_UP) {
       this.nome.requestFocusInWindow();}
     // TODO add your handling code here:
    }//GEN-LAST:event_cognomeKeyPressed

    private void indKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_indKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_DOWN | evt.getKeyCode() == KeyEvent.VK_ENTER) {
       this.piva.requestFocusInWindow();}
     if (evt.getKeyCode() == KeyEvent.VK_UP) {
       this.cognome.requestFocusInWindow();}// TODO add your handling code here:
    }//GEN-LAST:event_indKeyPressed

    private void pivaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_pivaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_DOWN | evt.getKeyCode() == KeyEvent.VK_ENTER) {
       this.tel1.requestFocusInWindow();}
     if (evt.getKeyCode() == KeyEvent.VK_UP) {
       this.ind.requestFocusInWindow();}// TODO add your handling code here:
    }//GEN-LAST:event_pivaKeyPressed

    private void tel1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tel1KeyPressed
   if (evt.getKeyCode() == KeyEvent.VK_DOWN | evt.getKeyCode() == KeyEvent.VK_ENTER) {
       this.tel2.requestFocusInWindow();}
     if (evt.getKeyCode() == KeyEvent.VK_UP) {
       this.piva.requestFocusInWindow();}//        // TODO add your handling code here:
    }//GEN-LAST:event_tel1KeyPressed

    private void tel2KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tel2KeyPressed
       if (evt.getKeyCode() == KeyEvent.VK_DOWN | evt.getKeyCode() == KeyEvent.VK_ENTER) {
       this.tel3.requestFocusInWindow();}
     if (evt.getKeyCode() == KeyEvent.VK_UP) {
       this.tel2.requestFocusInWindow();} // TODO add your handling code here:
    }//GEN-LAST:event_tel2KeyPressed

    private void tel3KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tel3KeyPressed
       if (evt.getKeyCode() == KeyEvent.VK_DOWN | evt.getKeyCode() == KeyEvent.VK_ENTER) {
       this.em1.requestFocusInWindow();}
     if (evt.getKeyCode() == KeyEvent.VK_UP) {
       this.tel2.requestFocusInWindow();} // TODO add your handling code here:
    }//GEN-LAST:event_tel3KeyPressed

    private void em1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_em1KeyPressed
       if (evt.getKeyCode() == KeyEvent.VK_DOWN | evt.getKeyCode() == KeyEvent.VK_ENTER) {
       this.em2.requestFocusInWindow();}
     if (evt.getKeyCode() == KeyEvent.VK_UP) {
       this.tel3.requestFocusInWindow();}   // TODO add your handling code here:
    }//GEN-LAST:event_em1KeyPressed

    private void em2KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_em2KeyPressed
       if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
       this.Salva.requestFocusInWindow();}
     if (evt.getKeyCode() == KeyEvent.VK_UP) {
       this.em1.requestFocusInWindow();} // TODO add your handling code here:
    }//GEN-LAST:event_em2KeyPressed

    private void SalvaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_SalvaKeyPressed
    if(evt.getKeyCode() == KeyEvent.VK_ENTER){  
    Confermasalva cs = new Confermasalva(parent2,true);
    cs.setVisible(true);
   if (cs.risposta()) {//se la form di conferma e' ok 
         String identificativo;
         if(this.rsoc.getText()==""){//controlla se c'e' solo la ragione sociale invece che un nominativo
          identificativo=this.cognome.getText()+" "+this.nome.getText();
         }
         else{
             identificativo=this.rsoc.getText()+" "+this.cognome.getText()+" "+this.nome.getText();
         }
              if (controllo(this.piva.getText(), "piva"))
         
           if (inserimento(identificativo,this.ind.getText(),this.piva.getText(),
                  this.tel1.getText(),this.tel2.getText(),this.tel3.getText(),this.em1.getText(),this.em2.getText(),tipo2)
              )
               
           {Errore err = new Errore (parent2,true);
               err.settitolo("Operazione Eseguita");
               err.setmessaggio("Record Salvato");
               err.setVisible(true);
               ans=true;
               this.setVisible(false);
               
               } 
           else {Errore err = new Errore (parent2,true);
               err.setmessaggio("Controlla i campi");
               err.setVisible(true);}
           else {Errore err = new Errore (parent2,true);
               err.setmessaggio("Partita iva già presente in archivio");
               err.setVisible(true);
         }  
   }}
    }//GEN-LAST:event_SalvaKeyPressed
       
    
        private void rsocKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_rsocKeyPressed
       if (evt.getKeyCode() == KeyEvent.VK_DOWN | evt.getKeyCode() == KeyEvent.VK_ENTER) {
       this.nome.requestFocusInWindow();}  // TODO add your handling code here:
    }//GEN-LAST:event_rsocKeyPressed
        
    
    public void Carica(String nome1,String indirizzo, String partiva,String telf1,String telf2,String telf3,String eml1,String eml2 ){
        this.nome.setText(nome1);
        this.ind.setText(indirizzo);
        this.piva.setText(partiva);
        this.tel1.setText(telf1);
        this.tel2.setText(telf2);
        this.tel3.setText(telf3);
        this.em1.setText(eml1);
        this.em2.setText(eml2);
    }
            
     
       
    /**
     * @param args the command line arguments
     */ 
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Salva;
    private javax.swing.JTextField cognome;
    private javax.swing.JTextField em1;
    private javax.swing.JTextField em2;
    private javax.swing.JTextField ind;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JToggleButton jToggleButton3;
    private javax.swing.JToggleButton jToggleButton5;
    private javax.swing.JTextField nome;
    private javax.swing.JPanel pannelloInfo;
    private javax.swing.JTextField piva;
    private javax.swing.JTextField rsoc;
    private javax.swing.JTextField tel1;
    private javax.swing.JTextField tel2;
    private javax.swing.JTextField tel3;
    private javax.swing.JLabel titolo;
    // End of variables declaration//GEN-END:variables

    private static Boolean controllo(java.lang.String value, java.lang.String key) {
        gruppo12.AnagraficaService_Service service = new gruppo12.AnagraficaService_Service();
        gruppo12.AnagraficaService port = service.getAnagraficaServicePort();
        return port.controllo(value, key);
    }

    private static Boolean inserimento(java.lang.String nome, java.lang.String indirizzo, java.lang.String piva, java.lang.String tel1, java.lang.String tel2, java.lang.String tel3, java.lang.String email1, java.lang.String email2, int tipo) {
        gruppo12.AnagraficaService_Service service = new gruppo12.AnagraficaService_Service();
        gruppo12.AnagraficaService port = service.getAnagraficaServicePort();
        return port.inserimento(nome, indirizzo, piva, tel1, tel2, tel3, email1, email2, tipo);
    }

    
}
